﻿using Core;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
using Verse.Sound;
using WhoXiuXian;
using static RimWorld.PsychicRitualRoleDef;

namespace RI_Talisman
{
    public class CompAbilityEffect_RI_MaterialDecomposition : CompAbilityEffect
    {
        public new CompProperties_RI_MaterialDecomposition Props => (CompProperties_RI_MaterialDecomposition)props;

        public override void Initialize(AbilityCompProperties props)
        {
            base.Initialize(props);
        }

        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            Building building = target.Cell.GetFirstBuilding(parent.pawn.Map);
            if (building.def==RI_T_DefOfs.RI_AncientCultivatorCryptosleepCasket) {
                ((RI_Building_AncientCultivatorCryptosleepCasket)building).Activate();
                return;
            }
            target.Cell.GetFirstBuilding(parent.pawn.Map).Destroy();
            foreach (ThingDefCount thingDefCount in building.CostListAdjusted()) {
                for (int i=0;i< thingDefCount.Count;i++) {
                    GenSpawn.Spawn(thingDefCount.ThingDef, target.Cell, parent.pawn.Map);
                }
            }
        }

        public override void CompTick()
        {
          
            base.CompTick();

        }
    }
}